package com.titar.robot.widgets;

import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.leaking.slideswitch.SlideSwitch;
import com.titar.robot.R;


/**
 * Created by TNT_17306 on 2017/4/10.
 */

public class TntToolbar extends LinearLayout implements View.OnClickListener {

    private View mToolbar;
    private TextView mTitle;
    private TextView mTextOk;
    private ImageView mIvLeft;
    private ImageView mIvRight;
    private TextView mNikename;
    private ImageView mIvRightSetting;
    private SlideSwitch mSlideSwitch;

    private SmoothCheckBox checkBox;
    private TextView cb_tv;
    private ImageView cb_iv;
    private TextView cb_tv2;


    public TntToolbar(Context context) {
        this(context, null);
    }

    public TntToolbar(Context context, AttributeSet attrs) {
        super(context, attrs);
        mToolbar = LayoutInflater.from(context).inflate(R.layout.layout_tool_bar, this, true);
        initView(context, attrs);
    }

    private void initView(Context context, AttributeSet attrs) {
        mTitle = (TextView) findViewById(R.id.toolbar_tv_title);
        mIvLeft = (ImageView) findViewById(R.id.toolbar_iv_left);
        mIvRight = (ImageView) findViewById(R.id.toolbar_iv_right);
        mIvRightSetting = (ImageView) findViewById(R.id.toolbar_iv_setting);
        mSlideSwitch = (SlideSwitch) findViewById(R.id.ss_toggle);
        mTextOk = (TextView) findViewById(R.id.toolbar_tx_ok);
        mNikename = (TextView) findViewById(R.id.toolbar_tv_nikename);

        checkBox = findViewById(R.id.tnt_toolbar_checkbox);
        cb_tv = findViewById(R.id.tnt_toolbar_cb_tv);
        cb_iv = findViewById(R.id.tnt_toolbar_cb_iv);
        cb_tv2 = findViewById(R.id.tnt_toolbar_cb_tv2);

        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.TntToolbar);
        mTitle.setText(typedArray.getString(R.styleable.TntToolbar_toolbarTitle));
        boolean isShowOk = typedArray.getBoolean(R.styleable.TntToolbar_showok, false);
        if (isShowOk) mTextOk.setVisibility(VISIBLE);
        typedArray.recycle();

        mIvLeft.setOnClickListener(this);
    }

    public View getToolbar() {
        return mToolbar;
    }

    public TextView getTitle() {
        return mTitle;
    }

    public ImageView getIvLeft() {
        return mIvLeft;
    }

    public ImageView getIvRight() {
        return mIvRight;
    }

    public TextView getTvRight() {
        return mTextOk;
    }

    public TextView getTvNikeName() {
        return mNikename;
    }

    public ImageView getIvRightSetting() {
        return mIvRightSetting;
    }

    public SmoothCheckBox getCheckBox() {
        return checkBox;
    }

    public ImageView getCb_iv() {
        return cb_iv;
    }

    public TextView getCb_tv() {
        return cb_tv;
    }

    public TextView getCb_tv2() {
        return cb_tv2;
    }

    public void setTextOk(String text, View.OnClickListener listener) {
        mTextOk.setVisibility(VISIBLE);
        mTextOk.setText(text);
        mTextOk.setOnClickListener(listener);

        //至于许显示一个/其他隐藏
        mIvRight.setVisibility(GONE);
        mIvRightSetting.setVisibility(GONE);
        mSlideSwitch.setVisibility(GONE);
    }


    public SlideSwitch getmSsToggle() {
        return mSlideSwitch;
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.toolbar_iv_left:
                if (getContext() instanceof Activity) {
                    ((Activity) getContext()).finish();
                }
                break;
        }
    }
}
